<template>
	<view class="mine">

		<view class="vip_content">
			<view class="small_t">
				开通VIP
			</view>
			<view class="title">
				<view class="name">
					开通VIP享受更多优惠
				</view>
				<view class="price">
					{{info.amountNum}}元/{{info.yearsNum}}年
				</view>
			</view>
			<view class="btn_box">
				<view @click="opvip" class="btn">
					立即开通
				</view>
			</view>
		</view>



		<view class="way">
			支付方式
		</view>

		<view class="pay_box">
			<view @click="tabs(1)" class="pay_item">
				<view class="pay_left">
					<image src="../../static/tabsIcon/payment/we.png" mode=""></image>
					<text>微信支付</text>
				</view>
				<view class="pay_right">
					<image v-if="act==1" src="../../static/tabsIcon/co1.png" mode=""></image>
					<image v-else src="../../static/tabsIcon/co2.png" mode=""></image>
				</view>
			</view>
			<view @click="tabs(2)" class="pay_item">
				<view class="pay_left">
					<image src="../../static/tabsIcon/payment/ali.png" mode=""></image>
					<text>支付宝</text>
				</view>
				<view class="pay_right">
					<image v-if="act==2" src="../../static/tabsIcon/co1.png" mode=""></image>
					<image v-else src="../../static/tabsIcon/co2.png" mode=""></image>
				</view>
			</view>
			<view @click="tabs(0)" class="pay_item">
				<view class="pay_left">
					<image src="../../static/tabsIcon/payment/ye.png" mode=""></image>
					<text>账户余额</text>
				</view>
				<view class="pay_right">
					<image v-if="act==0" src="../../static/tabsIcon/co1.png" mode=""></image>
					<image v-else src="../../static/tabsIcon/co2.png" mode=""></image>
				</view>
			</view>
		</view>

		<view class="mid">
			<!-- <image src="../../static/tabsIcon/vipquan.png" mode=""></image> -->
			<view class="vip_quantit">
				<text class="quan1">专属VIP</text>
				<text class="quan2">权益</text>
			</view>
		</view>

		<view class="info_detail">
			<view class="detail_item">
				<view class="nums">1.</view>
				<view class="item_info">自购省钱、分享赚钱：在淘宝、京东等购物平台享受自购省钱（平均分佣3%）、分享赚钱（平均分佣6%）的权益。</view>
			</view>
			<view class="detail_item">
				<view class="shuang"></view>
				<view class="nums">2.</view>
				<view class="item_info">购物即分红：在儒雅牛粉商城，购物即赠送牛角，参与商城利润分红。</view>
			</view>
			<view class="detail_item">
				<view class="nums">3.</view>
				<view class="item_info">线上知识视频：免费在线学习信用卡知识视频、财商视频。</view>
			</view>
			<view class="detail_item">
				<view class="shuang"></view>
				<view class="nums">4.</view>
				<view class="item_info">其他线下信用管理团队VIP所享受的一切权益。</view>
			</view>
<!-- 			<view class="detail_item">
				<view class="nums">5.</view>
				<view class="item_info">汇总信用卡最新福利积分活动 ，让VIP购物更省钱。</view>
			</view>
			<view class="detail_item">
				<view class="shuang"></view>
				<view class="nums">6.</view>
				<view class="item_info">解读银行最新信用卡政策。</view>
			</view>
			<view class="detail_item">
				<view class="nums">7.</view>
				<view class="item_info">线下一对一诊断梳理优化信用卡。</view>
			</view> -->
		</view>

		<!-- <view class="login_Box_protocol_contract">
			<view @click="contract = !contract" class="login_Box_protocol_contract_left">
				<view v-show="contract" class="login_Box_protocol_contract_left_bar">
				</view>
			</view>
			<view class="login_Box_protocol_contract_right">
				已阅读并同意《年费充值协议条款》
			</view>
		</view> -->
		<pay-keyboard @Fpassword="Fpassword" ref="password" :show_key="show_key" @hideFun="hideFun"
			@getPassword="getPassword"></pay-keyboard>
	</view>
</template>

<script>
	import payKeyboard from '@/components/keyboard.vue'
	import {
		getinfo,
		vipcardinfo,
		balancevip,
		alivip,
		wechatvip,
		checkpass
	} from '@/api/mine'
	export default {
		components: {
			payKeyboard: payKeyboard
		},
		data() {
			return {
				mine: [],
				info: [],
				act: 0,
				contract: false,
				paypass: '',
				show_key: false,
				pascheck: false,
			}
		},
		onLoad() {
			this.getinfo();
			this.vipcardinfo();
			this.checkpass()
		},
		methods: {
			checkpass() {
				checkpass().then(res => {
					this.pascheck = res.data;
				})
			},
			opvip() {
				// if (!this.contract) {
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: '请先阅读并同意《年费充值协议条款》'
				// 	})
				// 	return
				// }
				if (this.act == 0) {
					if (this.pascheck) {
						this.show_key = true;
					} else {
						uni.showToast({
							icon: 'none',
							title: '请先设置支付密码!'
						})
						setTimeout(() => {
							uni.navigateTo({
								url: './setpaypass'
							})
						}, 1000)
					}
				} else if (this.act == 2) {
					this.alivip()
				} else if (this.act == 1) {
					this.wechatvip()
				}
			},
			getPassword(n) {
				// console.log("用户输入的密码", n)
				this.paypass = n.password;
				this.$refs.password.clier();
				this.hideFun();
				this.balancevip();
			},
			Fpassword() {
				uni.navigateTo({
					url: "../mine/forgetpass",
				});
			},
			showFun() {
				this.show_key = true;
			},
			hideFun() {
				this.show_key = false;
			},
			balancevip() {
				let data = {
					password: this.paypass
				}
				balancevip(data).then(res => {
					if (res.success == 1) {
						uni.showToast({
							icon: 'none',
							title: '开通成功!'
						})
						setTimeout(() => {
							uni.switchTab({
								url: "./mine"
							})
						}, 1000)
					} else {
						uni.showToast({
							icon: 'none',
							title: res.message
						})
					}
				})
			},
			tabs(i) {
				this.act = i
			},
			vipcardinfo() {
				vipcardinfo().then(res => {
					if (res.success == 1) {
						this.info = res.data;
					} else {
						uni.showToast({
							icon: 'none',
							title: res.message
						})
					}
				})
			},
			alivip() {
				alivip().then(res => {
					if (res.success == 1) {
						uni.requestPayment({
							provider: 'alipay',
							orderInfo: res.data,
							success: function(res) {
								uni.showToast({
									icon: 'none',
									title: '开通成功!'
								})
								setTimeout(() => {
									uni.switchTab({
										url: "./mine"
									})
								}, 1000)
								console.log('success:' + JSON.stringify(res));
							},
							fail: function(err) {
								console.log('fail:' + JSON.stringify(err));
							}
						});
					} else {
						uni.showToast({
							icon: 'none',
							title: res.message
						})
					}
				})
			},
			wechatvip() {
				wechatvip().then(res => {
					if (res.success == 1) {
						uni.requestPayment({
							provider: 'wxpay',
							orderInfo: res.data,
							success: function(res) {
								uni.showToast({
									icon: 'none',
									title: '开通成功!'
								})
								setTimeout(() => {
									uni.switchTab({
										url: "./mine"
									})
								}, 1000)
								console.log('success:' + JSON.stringify(res));
							},
							fail: function(err) {
								console.log('fail:' + JSON.stringify(err));
							}
						});
					} else {
						uni.showToast({
							icon: 'none',
							title: res.message
						})
					}
				})
			},
			getinfo() {
				getinfo().then(res => {
						if (res.success == 1) {
							this.mine = res.data;
						} else {
							uni.showToast({
								icon: 'none',
								title: res.message
							})
						}
					})
					.catch(err => {

					});
			},
		}
	}
</script>

<style lang="scss">
	.mine {
		// background: #e7e9ec;
		// background-image: url(../../static/tabsIcon/mybg.webp);
		// background-repeat: no-repeat;
		// background-size: 100% 200rpx;
		// min-height: 80vh;
		padding: 40rpx;
	}


	.vip_content {
		background-image: url(../../static/tabsIcon/opvip.png);
		background-repeat: no-repeat;
		background-size: 100% 100%;
		border-radius: 10rpx;
		padding: 40rpx 15rpx;

		.small_t {
			color: #9A6C31;
			font-size: 24rpx;
		}

		.title {
			margin: 50rpx 0 46rpx;
			text-align: center;
			font-size: 40rpx;
			color: #8A5209;

			.name {
				font-weight: bold;
			}
		}

		.btn_box {
			display: flex;
			align-items: center;
			justify-content: center;
		}

		.btn {
			color: #FFFFFF;
			font-size: 30rpx;
			width: 80%;
			text-align: center;
			height: 80rpx;
			line-height: 80rpx;
			background: #8A5209;
			border-radius: 30rpx;
		}
	}

	.mid {
		display: flex;
		align-items: center;
		justify-content: center;

		image {
			width: 260rpx;
			height: 100rpx;
		}
	}


	.info_detail {
		margin-top: 40rpx;
		font-size: 32rpx;

		.detail_item {
			margin-bottom: 40rpx;
			display: flex;
			align-items: center;

			.nums {
				color: #FC6758;
				font-size: 60rpx;
				margin-right: 10rpx;
			}

			.item_info {
				color: #333333;
				font-size: 30rpx;
			}
		}

		.shuang {
			display: inline-block;
			width: 100rpx;
		}
	}

	.way {
		color: #666666;
		font-size: 30rpx;
		margin: 20rpx 0;
	}

	.pay_box {
		margin: 20rpx 0;

		.pay_item {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin: 20rpx 0 40rpx;

			.pay_left {
				color: #333333;
				font-size: 26rpx;
				display: flex;
				align-items: center;

				image {
					width: 50rpx;
					height: 50rpx;
					margin-right: 20rpx;
				}
			}

			.pay_right {
				image {
					width: 25rpx;
					height: 25rpx;
				}

			}
		}
	}

	.login_Box_protocol_contract {
		margin-top: 40upx;
		display: flex;
		align-items: center;
		justify-content: center;
		position: relative;

		.login_Box_protocol_contract_mack {
			position: absolute;
			bottom: -16upx;
			transform: translateY(100%);
			left: -30upx;
			padding: 20upx 30upx;
			border-radius: 20upx;
			background-color: rgba(0, 0, 0, 0.61);
			font-size: 34upx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: rgba(0, 0, 0, 0.8);
			line-height: 44upx;

			.login_Box_protocol_contract_mack_arrow {
				position: absolute;
				border: 10upx solid rgba(0, 0, 0, 0.61);
				top: 0;
				transform: translateY(-100%);
				left: 30upx;
				border-top-color: rgba(0, 0, 0, 0);
				border-left-color: rgba(0, 0, 0, 0);
				border-right-color: rgba(0, 0, 0, 0);
			}
		}

		.login_Box_protocol_contract_left {
			display: flex;
			justify-content: center;
			align-items: center;
			border: 2upx solid #000;
			border-radius: 100%;
			width: 28upx;
			height: 28upx;
			position: relative;

			.login_Box_protocol_contract_left_bar {
				width: 16upx;
				height: 16upx;
				// position: absolute;
				// top: 50%;
				// left: 50%;
				// transform: translate(-50% , -50%);
				background-color: #FF731E;
				border-radius: 100%;
			}
		}

		.login_Box_protocol_contract_right {
			margin-left: 18upx;
			width: calc(100% - 18upx - 28upx - 2upx);
			font-size: 24upx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: rgba(0, 0, 0, 0.9);
			line-height: 34upx;
		}
	}

	.login_Box_content_cont_button {
		margin-top: 36upx;
		height: 102upx;
		background: #FC8301;
		border-radius: 52upx;
		z-index: 23;
		height: 51px;
		background: url(../../static/loginButtonBG.png) 100% no-repeat;
		justify-content: center;
		align-items: center;
		border: none;
		display: flex;
		font-size: 36upx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: rgba(255, 255, 255, 0.8);
		line-height: 50upx;
	}
	.vip_quantit{
		border-bottom: 10rpx solid #fdb2ab;
		color: #494949;
		margin-top: 20rpx;
		.quan1{
			font-size: 50rpx;
		}
		.quan2{
			font-size: 29rpx;
		}
	}
</style>
